package com.ccx.coachsite.weibo.auth2;


import android.text.TextUtils;

import com.ccx.coachsite.weibo.json.JSONException;
import com.ccx.coachsite.weibo.json.JSONObject;


/**
 * 微博常量
 * @author zhuchenghua
 *
 */
public class WeiBoContants {
	
/***********************************************文件保存路径常量************************************************************/
	/**
	 * 缓存主目录
	 */
	public final static String WEIBO_WIDGET_BASE_DIR="/sdcard/YYZL/caches/weibowidget/";
	/**
	 * 资源缓存的目录，图片等
	 */
	public final static String WEIBO_COMMON_CACHE_DIR=WEIBO_WIDGET_BASE_DIR+"common/";
	/**
	 * 图片保存的目录
	 */
	public final static String WEIBO_IMAGE_SAVE_PATH="/sdcard/WeiBoImage/";
	
	
/***********************************************Intent传播数据的KEY************************************************************/
	/**
	 * Intent传递微博对象
	 */
	public final static String EXTRA_STATUS="extra_status";
	/**
	 * Intent传递评论对象
	 */
	public final static String EXTRA_COMMENT="extra_comment";
	/**
	 * Intent传递用户对象
	 */
	public final static String EXTRA_USER="extra_user";
	/**
	 * Intent传递列表索引
	 */
	public final static String EXTRA_POS="extra_pos";
	/**
	 * Intent传递是否添加新用户的标志
	 */
	public final static String EXTRA_IS_ADD_USER="extra_is_add_user";
	/**
	 * Intent传递集合
	 */
	public final static String EXTRA_LIST="extra_list";
	
	/**
	 * Intent传递是否已关注
	 */
	public final static String EXTRA_IS_FRIEND="extra_is_friend";
	
	/**
	 * Intent传递用户名
	 */
	public final static String EXTRA_USER_NAME="extra_user_name";
	
	/**
	 * Intent传递用户ID
	 */
	public final static String EXTRA_USER_ID="extra_user_id";
	
	
	/**
	 * Intent传递桌面类型
	 */
	public final static String EXTRA_DESK_TYPE="extra_desk_type";
	
/***********************************************广播KEY************************************************************/
	/**
	 * 添加或取消关注的广播
	 */
	public final static String BROADCAST_ADD_OR_REMOVE_FRIEND="broadcast.add.or.remove.friend";
	/**
	 *  登录事件监听
	 */
	public final static String BROADCAST_LOGIN_ACTION = "weibo.widget.receiver.login.action";
	/**
	 *  用户切换事件监听
	 */
	public final static String BROADCAST_CHANGE_USER = "weibo.widget.receiver.change.user";
	/**
	 * 用户切换完成监听
	 */
	public final static String BROADCAST_CHANGE_USER_SUCCESS="weibo.widget.receiver.change.user.success";
	
	/**
	 * 加载新微博的监听
	 */
	public final static String BROADCAST_LOAD_NEW_WEIBO_REQUEST="weibo.widget.receiver.load.new.data.request";
	/**
	 * 加载微博的 评论与转发数的监听
	 */
	public final static String BROADCAST_RELOAD_COMMENT_AND_REPOST_COUNT_REQUEST="weibo.widget.receiver.reload.comment.and.repost.count.request";
	/**
	 * 重新布局监听
	 */
	public final static String BROADCAST_RELAYOUT_REQUEST="weibo.widget.receiver.relayout.request";
	
/***********************************************内部类************************************************************/
	
	/**
	 * 这两个分别是熊猫桌面的应用标识与密钥，是从新浪申请而来。
	 */
	public static class App{
		
		/**熊猫桌面的App Key 和 Secret*/
		public final static String CONSUMER_KEY_PANDA_HOME="1548213697";
		public final static String CONSUMER_SECRET_PANDA_HOME="020297f0fb3b4f61b6ee640dac7bef69";
		/**熊猫桌面包名*/
		public final static String PANDA_HOME_PACKAGE="com.nd.android.pandahome2";
	}
	
	/**
	 * 
	 * 用户授权的常量，及保存requestToken临时对象
	 */
	public static class Auth{
		
		/**微博授权地址*/
		public static final String WEIBO_AUTH_URL="https://api.weibo.com/oauth2/access_token";
		
		public static final int OK = 200;// OK: Success!
		
	}//end Auth
	
	/**
	 * 关于微博信息操作的常量
	 */
	public static class WeiBo{
		
		/**微博接口地址前缀*/
		public static final String WEIBO_SERVER="https://api.weibo.com/2/";
		
		/**
		 * 发送微博,带图片的地址
		 */
		public final static String SEND_WEIBO_PIC_URL =WEIBO_SERVER+"statuses/upload.json";
		/**
		 * 发送微博,纯文本的地址
		 */
		public final static String SEND_WEIBO_URL = WEIBO_SERVER+"statuses/update.json";
		
		/**
		 * 获取当前登录用户及其所关注用户的最新微博消息(默认20条，可以传参指定返回条数)的地址。
		 */
		public final static String GET_CURRENT_USER_WEIBO_URL=WEIBO_SERVER+"statuses/friends_timeline.json";
		
		/**
		 * 转发一条微博消息的地址
		 */
		public final static String REPOST_WEIBO_URL=WEIBO_SERVER+"statuses/repost.json";
		
		/**
		 * 对一条微博信息进行评论
		 */
		public final static String COMMENT_WEIBO_URL=WEIBO_SERVER+"comments/create.json";
		
		/**
		 * 回复一条评论 
		 */
		public final static String COMMENT_REPLY_URL=WEIBO_SERVER+"comments/reply.json";
		
		/**
		 * 批量获取n条微博消息的评论数和转发数的URL
		 */
		public final static String GET_COUNTS_URL=WEIBO_SERVER+"statuses/count.json";
		
		/**
		 * 根据ID删除微博消息。
		 */
		public final static String DELETE_WEIBO_URL=WEIBO_SERVER+"statuses/destroy.json";
		
		/**根据微博ID获取单条微博内容*/
		public final static String GET_WEIBO_BY_ID_URL=WEIBO_SERVER+"statuses/show.json";
		
		
		/**
		 * 按用户ID或昵称返回用户资料以及用户的最新发布的一条微博消息。 
		 */
		public final static String GET_USER_URL=WEIBO_SERVER+"users/show.json";
		
		/**
		 * 返回最新n条提到登录用户的微博消息（即包含@username的微博消息）  
		 */
		public final static String GET_WEIBO_AT_ME_URL=WEIBO_SERVER+"statuses/mentions.json";
		
		/**
		 * 返回用户最新发表的微博消息列表。  
		 */
		public final static String GET_USER_TIMELINE_URL=WEIBO_SERVER+"statuses/user_timeline.json";
		
		/**
		 * 获取用户关注列表及每个关注用户的最新一条微博，返回结果按关注时间倒序排列，最新关注的用户排在最前面  
		 */
		public final static String GET_USER_FIRENDS_URL=WEIBO_SERVER+"friendships/friends.json";
		/**
		 * 添加对某用户的关注  
		 */
		public final static String ADD_FIRENDS_URL=WEIBO_SERVER+"friendships/create.json";
		
		/**
		 * 取消对某用户的关注  (REST风格的)
		 */
		public final static String REMOVE_FIRENDS_URL=WEIBO_SERVER+"friendships/destroy.json";
		/**
		 * 获取用户粉丝列表及及每个粉丝用户最新一条微博 
		 */
		public final static String GET_USER_FOLLOWERS_URL=WEIBO_SERVER+"friendships/followers.json";
		/**
		 * 返回用户关注的一组用户的ID列表 
		 */
		public final static String GET_USER_FRIEND_IDS_URL=WEIBO_SERVER+"friendships/followers/ids.json";
		
		/**
		 * 返回当前登录用户收到的评论
		 */
		public final static String GET_COMMENTS_TO_ME_URL=WEIBO_SERVER+"comments/to_me.json";
		/**
		 *删除用户收到的评论
		 */
		public final static String DELETE_COMMENTS_TO_ME_URL=WEIBO_SERVER+"comments/destroy.json";
	}
	
	/**
	 * 微博注册的相关常量
	 */
	public static class Register{
		
		/**
		 * 打开微博注册界面的requestCode;
		 */
		public final static int REQUEST_CODE_WEIBO_REGIST=10000; 
		
		/**
		 * 微博注册界面返回的resultCode;
		 */
		public final static int RESULT_CODE_WEIBO_REGIST=11000; 
		
		
		/**
		 * 获取验证码地址
		 */
		public final static String GET_VERIFY_URL = "http://api.weibo.cn/interface/f/ttt/captcha/get.php";

		/**
		 * 新浪微博注册地址
		 */
		public final static String REGISTER_URL = "http://pandahome.sj.91.com/theme.ashx/weiboreg";
		
		/**
		 * 新浪微博注册地址(网页方式)
		 */
		public final static String REGISTER_WEB_URL="http://weibo.cn/dpool/ttt/h5/reg.php?wm=0&act=card";
		
		/**
		 * 新浪微博注册(短信方式的号码)
		 */
		public final static String REGISTER_MSG_NUMBER="1069009088";

		/**
		 * 渠道ID，新浪给的
		 */
		public final static String WM = "4112";

		/**
		 * 合作ID，新浪给的
		 */
		public final static String COM_ID = "27";

		/**
		 * 密钥，新浪给的
		 */
		public final static String MD5_SECRETE = "l65pc6fucDgHdBcxcQ4z3uFYGORxfMyM";
		
		/**
		 * 登录名的后缀，真的是用户名是界面填写的用户名+@91.com
		 */
		public final static String loginNameSuffix="@91.com";
		
	}//end Register
	
	/**
	 * 微博登录相关常量
	 */
	public static class Login{
		
		/**
		 * Intent之间传递值的微博登录结果,传的是boolean型数据
		 */
		public final static String EXTRA_WEIBO_LOGIN_RESULT="extra_weibo_login_result";
		
		/**
		 * 微博登录界面返回的结果码
		 */
		public final static int RESULT_CODE_WEIBO_LOGIN=100000;
		
		/**
		 * 打开微博登录界面的requestCode;
		 */
	    public final static int REQUEST_CODE_WEIBO_LOGIN=1000;
	}
	
	/**
	 * Activity跳转的requestCode,在startActivityForResult中用
	 */
	public static class Request{
		/**
		 * 添加帐号时的 ActivityResult的request code
		 */
		public final static int REQUEST_CODE_ADD_USER=30000;
		
	}
	
	/**
	 * Handler 的消息常用的Key
	 */
	public static class HandlerEvent{
		
		/**
		 * 用户资料界面-->导航条，初始化
		 */
		public final static int EVENT_INIT_USER_INFO_NAVIGATOR=19000;
	}
	
	
/*******************************自定义方法***********************************************************************/
	
	/**登陆过期的错误码*/
	public static final int STATUS_CODE_TOKEN_INVALIDATE=21327; 
	
	private static JSONObject mJSONObj=null;
	/**
	 * 获取出错提示
	 * @param statusCode
	 * @return
	 */
	public static String getCause(int statusCode){
		
		String cause = null;
		if(mJSONObj!=null){
			try {
				cause=mJSONObj.getString(String.valueOf(statusCode));
			} catch (JSONException e) {
			}
		}else{
			try {
				mJSONObj=new JSONObject("{" +
					    "\"10001\":\"系统错误\","+
					    "\"10002\":\"服务端资源不可用\","+
					    "\"10003\":\"远程服务出错\","+
					    "\"10005\":\" 该资源需要appkey拥有更高级的授权\","+
					    "\"10006\":\"缺少 source参数(appkey)\","+
					    "\"10007\":\"不支持的 MediaType (%s)\","+
					    "\"10008\":\"错误:参数错误，请参考API文档\","+
					    "\"10009\":\"任务过多，系统繁忙\","+
					    "\"10010\":\"任务超时\","+
					    "\"10011\":\"RPC错误\","+
					    "\"10012\":\"非法请求\","+
					    "\"10013\":\"不合法的微博用户\","+
					    "\"10014\":\"第三方应用访问api接口权限受限制\","+
					    "\"10016\":\"错误:缺失必选参数:%s，请参考API文档\","+
					    "\"10017\":\"错误:参数值非法,希望得到 (%s),实际得到 (%s)，请参考API文档\","+
					    "\"10018\":\"请求长度超过限制\","+
					    "\"10020\":\"接口不存在\","+
					    "\"10021\":\"请求的HTTP METHOD不支持\","+
					    "\"10022\":\"IP请求超过上限\","+
					    "\"10023\":\"用户请求超过上限\","+
					    "\"10024\":\"用户请求接口%s超过上限\","+
					    "\"10025\":\"内部接口参数错误\","+
					    "\"20001\":\"IDS参数为空\","+
					    "\"20002\":\"uid参数为空\","+
					    "\"20003\":\"用户不存在\","+
					    "\"20005\":\"不支持的图片类型,仅仅支持JPG,GIF,PNG\","+
					    "\"20006\":\"图片太大\","+
					    "\"20007\":\"请确保使用multpart上传了图片\","+
					    "\"20008\":\"内容为空\","+
					    "\"20009\":\"id列表太长了\","+
					    "\"20012\":\"输入文字太长，请确认不超过140个字符\","+
					    "\"20013\":\"输入文字太长，请确认不超过300个字符\","+
					    "\"20014\":\"传入参数有误，请再调用一次\","+
					    "\"20016\":\"发微博太多啦，休息一会儿吧\","+
					    "\"20017\":\"你刚刚已经发送过相似内容了哦，先休息一会吧\","+
					    "\"20019\":\"不要太贪心哦，发一次就够啦\","+
					    "\"20023\":\"很抱歉，此功能暂时无法使用，如需帮助请联系@微博客服 或者致电客服电话400 690 0000\","+
					    "\"20031\":\"需要弹出验证码\","+
					    "\"20032\":\"微博发布成功。目前服务器数据同步可能会有延迟，请耐心等待1-2分钟。谢谢\","+
					    "\"20033\":\"登陆状态异常\","+
					    "\"20101\":\"不存在的微博\","+
					    "\"20102\":\"不是你发布的微博\","+
					    "\"20103\":\"不能转发自己的微博\","+
					    "\"20109\":\"微博 id为空\","+
					    "\"20111\":\"不能发布相同的微博\","+
					    "\"20112\":\"由于作者隐私设置，你没有权限查看此微博\","+
					    "\"20114\":\"标签名太长\","+
					    "\"20115\":\"标签不存在\","+
					    "\"20116\":\"标签已存在\","+
					    "\"20117\":\"最多200个标签\","+
					    "\"20118\":\"最多5个标签\","+
					    "\"20119\":\"标签搜索失败\","+
					    "\"20120\":\"由于作者设置了可见性，你没有权限转发此微博\","+
					    "\"20121\":\"visible参数非法\","+
					    "\"20122\":\"应用不存在\","+
					    "\"20123\":\"最多屏蔽200个应用\","+
					    "\"20124\":\"最多屏蔽500条微博\","+
					    "\"20125\":\"没有屏蔽过此应用\","+
					    "\"20126\":\"不能屏蔽新浪应用\","+
					    "\"20127\":\"已添加了此屏蔽\","+
					    "\"20128\":\"删除屏蔽失败\","+
					    "\"20129\":\"没有屏蔽任何应用\","+
					    "\"20201\":\"不存在的微博评论\","+
					    "\"20203\":\"不是你发布的评论\","+
					    "\"20204\":\"评论ID为空\","+
					    "\"20206\":\"作者只允许关注用户评论\","+
					    "\"20207\":\"作者只允许可信用户评论\","+
					    "\"20401\":\"域名不存在\","+
					    "\"20402\":\"verifier错误\","+
					    "\"20403\":\"屏蔽用户列表中存在此uid\","+
					    "\"20404\":\"屏蔽用户列表中不存在此uid\","+
					    "\"20405\":\"uid对应用户不是登录用户的好友\","+
					    "\"20406\":\"屏蔽用户个数超出上限\","+
					    "\"20407\":\"没有合适的uid\","+
					    "\"20408\":\"从feed屏蔽列表中，处理用户失败\","+
					    "\"20501\":\"错误:source_user 或者target_user用户不存在\","+
					    "\"20502\":\"必须输入目标用户id或者 screen_name\","+
					    "\"20503\":\"关系错误，user_id必须是你关注的用户\","+
					    "\"20504\":\"你不能关注自己\","+
					    "\"20505\":\"加关注请求超过上限\","+
					    "\"20506\":\"已经关注此用户\","+
					    "\"20507\":\"需要输入验证码\","+
					    "\"20508\":\"根据对方的设置，你不能进行此操作\","+
					    "\"20509\":\"悄悄关注个数到达上限\","+
					    "\"20510\":\"不是悄悄关注人\","+
					    "\"20511\":\"已经悄悄关注此用户\","+
					    "\"20512\":\"你已经把此用户加入黑名单，加关注前请先解除\","+
					    "\"20513\":\"你的关注人数已达上限\","+
					    "\"20522\":\"还未关注此用户\","+
					    "\"20523\":\"还不是粉丝\","+
					    "\"20601\":\"列表名太长，请确保输入的文本不超过10个字符\","+
					    "\"20602\":\"列表描叙太长，请确保输入的文本不超过70个字符\","+
					    "\"20603\":\"列表不存在\","+
					    "\"20604\":\"不是对象所属者\","+
					    "\"20605\":\"列表名或描叙不合法\","+
					    "\"20606\":\"记录已存在\","+
					    "\"20607\":\"错误:数据库错误，请联系系统管理员\","+
					    "\"20608\":\"列表名冲突\","+
					    "\"20610\":\"目前不支持私有分组\","+
					    "\"20611\":\"创建list失败\","+
					    "\"20612\":\"目前只支持私有分组\","+
					    "\"20613\":\"错误:不能创建更多的列表\","+
					    "\"20614\":\"已拥有列表上下，请参考API文档\","+
					    "\"20615\":\"成员上线，请参考API文档\","+
					    "\"20616\":\"不支持的分组类型\","+
					    "\"20617\":\"最大返回300条\","+
					    "\"20618\":\"uid 不在列表中\","+
					    "\"20701\":\"不能提交相同的标签\","+
					    "\"20702\":\"最多两个标签\","+
					    "\"20704\":\"您已经收藏了此微博\","+
					    "\"20705\":\"此微博不是您的收藏\","+
					    "\"20706\":\"操作失败\","+
					    "\"20801\":\"trend_name是空值\","+
					    "\"20802\":\"trend_id是空值\","+
					    "\"21001\":\"标签参数为空\","+
					    "\"21002\":\"标签名太长，请确保每个标签名不超过14个字符\","+
					    "\"21103\":\"该用户已经绑定手机\","+
					    "\"21104\":\"verifier错误\","+
					    "\"21105\":\"你的手机号近期频繁绑定过多个帐号，如果想要继续绑定此帐号，请拨打客服电话400 690 0000申请绑定\","+
					    "\"21108\":\"原始密码错误\","+
					    "\"21109\":\"新密码错误\","+
					    "\"21110\":\"此用户暂时没有绑定手机\","+
					    "\"21113\":\"教育信息不存在\","+
					    "\"21115\":\"职业信息不存在\","+
					    "\"21117\":\"此用户没有qq信息\","+
					    "\"21120\":\"此用户没有微号信息\","+
					    "\"21121\":\"此微号已经存在\","+
					    "\"21301\":\"认证失败\","+
					    "\"21302\":\"用户名或密码不正确\","+
					    "\"21303\":\"用户名密码认证超过请求限制\","+
					    "\"21304\":\"版本号错误\","+
					    "\"21305\":\"缺少必要的参数\","+
					    "\"21306\":\"Oauth参数被拒绝\","+
					    "\"21307\":\"时间戳不正确\","+
					    "\"21308\":\"nonce参数已经被使用\","+
					    "\"21309\":\"签名算法不支持\","+
					    "\"21310\":\"签名值不合法\","+
					    "\"21311\":\"consumer_key不存在\","+
					    "\"21312\":\"consumer_key不合法\","+
					    "\"21313\":\"consumer_key缺失\","+
					    "\"21314\":\"Token已经被使用\","+
					    "\"21315\":\"Token已经过期\","+
					    "\"21316\":\"Token不合法\","+
					    "\"21317\":\"Token不合法\","+
					    "\"21318\":\"Pin码认证失败\","+
					    "\"21319\":\"授权关系已经被解除\","+
					    "\"21320\":\"不支持的协议\","+
					    "\"21321\":\"未审核的应用使用人数超过限制\","+
					    "\"21322\":\"重定向地址不匹配\","+
					    "\"21323\":\"请求不合法\","+
					    "\"21324\":\"client_id或client_secret参数无效\","+
					    "\"21325\":\"帐号或密码有不正确\","+
					    "\"21326\":\"客户端没有权限\","+
					    "\"21327\":\"token过期\","+
					    "\"21328\":\"不支持的 GrantType\","+
					    "\"21329\":\"不支持的 ResponseType\","+
					    "\"21330\":\"用户或授权服务器拒绝授予数据访问权限\","+
					    "\"21331\":\"服务暂时无法访问\","+
					    "\"21332\":\"access_token 无效\","+
					    "\"21333\":\"禁止使用此认证方式 \" "+
						"}");
				cause=mJSONObj.getString(String.valueOf(statusCode));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		if(TextUtils.isEmpty(cause))
			cause = "未知错误，请重试";
		return cause;
		
    }//end getCause

}

















